package mvc;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import action.LoginAction;
import action.ZhuceAction;

import form.Action;
import form.ActionForm;
import form.loginform;
import form.zhuCe;

import unti.FullBean;

public class ActionServlet extends HttpServlet {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
       // System.out.println("sign="+request.getParameter("sign"));
	//	String sign=request.getParameter("sign");
//		loginform form=(loginform)FullBean.full(request.getParameter("sign"), request);
//		System.out.println(form);
		
//		zhuCe ce=(zhuCe)FullBean.full(request.getParameter("sign"), request);
//		System.out.println(ce);
		
		ActionForm form=FullBean.full(request);
		Action action=null;
		
		
		Map<String,String> map=ActionMapping.getMap();
		try{
			String actionname=map.get(request.getParameter("sign"));
			Class clazz=Class.forName(actionname);
			action=(Action)clazz.newInstance();
		}catch(Exception e){
			
		}
//		if(request.getParameter("sign").equals("form.loginform")){
//			action=new LoginAction();
//		}
//		if(request.getParameter("sign").equals("form.zhuCe")){
//			action=new ZhuceAction();
//		}
		String message=action.execute(form);
		PrintWriter out=response.getWriter();
		System.out.println(message);

	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	  this.doGet(request, response);
	}

	

}
